<template>
  <div v-if="comment_item">
    <div class="comment_item">
      <div class="comment_top">
        <div class="user">
          <div class="img_photo">
            <img :src="$axios.defaults.baseURL+ comment_item.user.head_img" alt />
          </div>
          <span>{{comment_item.user.nickname}}</span>
        </div>
        <span class="reply" @click="reply">评论</span>
      </div>
      <div class="comment_main">
        <p>{{comment_item.content}}</p>
        <!-- 调用秭归组件 -->
        <commentSon v-if="comment_item.parent" :parent="comment_item.parent" @reply="reply_son"></commentSon>
        <!-- 调用秭归组件 -->
      </div>
    </div>
  </div>
</template>

<script>
import commentSon from "./commentSon";
export default {
  props: ["comment_item"],
  methods: {
    reply() {
      // 子传父
      this.$emit("reply", this.comment_item.id);
    },
    reply_son(id) {
      // 接受递归组件的 子传父 而后 再 子传父
      this.$emit("reply", id);
    }
  },
  components: {
    commentSon
  }
};
</script>

<style lang="less" scoped>
.comment_item {
  padding: 2.778vw;
  .comment_top {
    display: flex;
    justify-content: space-between;
    .user {
      display: flex;
      align-items: center;
      span {
        padding-left: 5.556vw;
        font-size: 3.889vw;
        width: 44.445vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .img_photo {
        object-fit: cover;
        width: 13.889vw;
        height: 13.889vw;
        img {
          border: 1px solid #ccc;
          border-radius: 4.167vw;
          width: 100%;
          height: 100%;
        }
      }
    }
    // 回复
    .reply {
      padding: 5.556vw;
      font-size: 3.889vw;
    }
  }
  .comment_main {
    margin-top: 5.556vw;
    display: flex;
    flex-wrap: wrap;
    > p {
      width: 83.333vw;
      padding: 2.222vw;
      font-size: 18px;
      font-weight: 700;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>